package com.wanmait.bootdemo.controller;

import com.wanmait.bootdemo.pojo.QuestionType;
import com.wanmait.bootdemo.service.QuestionTypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/manage/questionType")
//放在控制器类上，该控制器所有的功能处理方法都允许跨域请求 可以放在方法上
//orgins指定哪些域名可以跨域访问当前的接口，如果不指定orgins默认所有的域名都可以跨域来访问
//@CrossOrigin(origins = {"http://www.wanmait.com","http://127.0.0.1:6327/"})
//@CrossOrigin
public class QuestionTypeController {

    @Resource
    private QuestionTypeService questionTypeService;

    @RequestMapping("list")
    //@ResponseBody
    public List<QuestionType> list(){
        return questionTypeService.findAll();
    }

    @PostMapping("insert")
    //@ResponseBody
    public String insert(@RequestBody QuestionType questionType){
        questionTypeService.insert(questionType);
        return "ok";
    }


    @RequestMapping("{id:\\d+}")
    //@ResponseBody
    public QuestionType findById(@PathVariable Integer id){
        QuestionType questionType = new QuestionType();
        questionType.setId(id);
        questionType.setTitle("java数据库"+id);
        questionType.setSort(111);
        return  questionType;
    }

}
